import Vue from 'vue'
import VueRouter, { RouteConfig } from 'vue-router'
import Home from '../views/Home.vue';
import store from '../store';

Vue.use(VueRouter)

  const routes: Array<RouteConfig> = [
    {
      path: '/',
      name: 'Home',
      component: Home,
      meta: { title: '首页'},
    },
]

const router = new VueRouter({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  store.commit('setRouterName', { routerName: to.meta.title || '首页' });
  store.commit('setRouterUrl', { routerUrl: to.fullPath || '/' })
  next();
})

export default router
